package online.hxstart.code.java8.chapter03;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import lombok.Data;

/**
 * @author huxing
 * @date 2019/6/20 星期四 19:21
 * @describe
 */
public class LambdaTest {


  public static <T, R> List<R> map(List<T> list, Function<T, R> f) {

    List<R> res = new ArrayList<>();
    for (T t : list) {
      res.add(f.apply(t));
    }

    return res;
  }

  public static void main(String[] args) {
    List<String> test = Arrays.asList("1111", "#2132", "321321", "42132321", "42432432432");
    List<Integer> list = map(test, (String s) -> s.indexOf("1"));
    System.out.println(list);

    System.out.println(comput(1, a -> a + 5 + 5));
  }

  public static <T> T comput(T t, Function<T, T> f) {

    return f.apply(t);
  }

  public static <T> T compute(T a, Function<T, T> function1, Function<T, T> function2) {
    return function1.compose(function2).apply(a);

  }


}

@Data
class Apple {

  private String color;
  private int weight;
}
